<template>
  <div>
    <mt-header title="添加就诊人" style="background-color: white; color: black">
      <div @click="$router.go(-1)" slot="left">
        <mt-button icon="back" style="color: black"></mt-button>
      </div>
    </mt-header>

    <div class="form">
      <div class="patirntList">
        <div class="patName"><span class="nameText">就诊人姓名</span>&nbsp;<span class="redd">*</span>&nbsp;<span class="redd">只可输入汉字、字母等字符</span></div>
        <input class="shuru" type="text" v-model="name" @blur="names" maxlength="6" placeholder="请输入就诊人姓名" />
      </div>
       <div class="patirntList">
        <div class="patName"><span class="nameText">就诊人手机号</span>&nbsp;<span class="redd">*</span></div>
        <input class="shuru" type="text" v-model="phone" @blur="phones" maxlength="11" placeholder="请输入就诊人手机号" />
      </div>
       <div class="patirntList">
        <div class="patName"><span class="nameText">有效证件号</span>&nbsp;<span class="redd">*</span>&nbsp;<span class="redd">只可输入汉字、字母等字符</span></div>
        <input class="shuru" type="text" v-model="identity" @blur="identitys" maxlength="18" placeholder="请输入有效证件号" />
      </div>
    </div>  
   
    <button class="butt" @click="getData">确定</button>

  </div>

 
</template>

<script>
export default {
  data() {
    return {
      name:'',
      phone:'',
      identity:'',
    }
  },
  methods:{
    names(){
      let gt = this.name.indexOf('<')
      let lt = this.name.indexOf('>')
      if(gt != -1 || lt != -1){
        this.$toast({
          message: '请输入去掉特殊字符',
          position: 'center',
          duration: 1500
        });
      }else{
        return true
      }
    },
    phones(){
      const phoneReg = /^[1][3,4,5,7,8][0-9]{9}$/;
      if(!phoneReg.test(this.phone.trim())){
        this.$toast({
          message: '请输入有效的手机号',
          position: 'center',
          duration: 1500
        });
      }else{
        return true
      }
    },
    identitys(){
      const reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
      if(!reg.test(this.identity.trim())){
        this.$toast({
          message: '请输入有效身份证件',
          position: 'center',
          duration: 1500
        });
      }else{
        return true
      }
    },
    getData(){
      if(this.names() && this.phones() && this.identitys()){
        // my_see存的用户的id 17
        let parms = `yhid=${this.$store.state.phone}&mname=${this.name}&ID_card=${this.phone}&phone=${this.identity}`
       
        this.axios.post(`/my_see`,parms).then(res=>{
          if(res.data.code == 200){
            this.$router.push('/patient')
          }
        })
      }
      
    },
  },

};
</script scoped>

<style lang="scss">
.form{
  padding: 0 3vh;
  box-sizing: border-box;
}
.nameText{
  font-weight: 600;
  font-size: 16px;
}
.patirntList{
  margin-top: 10px;
  border-bottom: 1px solid #DEDEDE;
}
.redd{
  font-size: 14px;
  color: red;
}
.shuru{
  margin: 12px 0;
  border: none;
}
.butt{
  background-color: #00D4B8;
  border-radius: 28px;
  padding: 15px 10px;
  box-sizing: border-box;
  border: none;
  width: 200px;
  color: white;
  position: fixed;
  bottom:30px;
  left: 25%;
}

</style>